#include "chatlist.h"
#include "ui_chatlist.h"
#include<QMovie>
#include<QFile>
#include<QFileInfo>
#include<QNetworkAccessManager>//网络连接管理
#include<QFileDialog>
#include<QIODevice>
#include<QNetworkRequest>
#include<QNetworkReply>
#include<QDebug>
#include<QJsonParseError>
#include<QJsonDocument>
#include<QJsonObject>
#include<QJsonValue>
#include"weather.h"
#include<QEvent>
#include<QHoverEvent>
#include<QVector>
#include<QToolButton>
#include<QPixmap>
#include<QSize>
#include"chat.h"
#include"loginwidget.h"
#include<QRegion>
#include "xingzuo.h"

chatlist::chatlist(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::chatlist)
{
    ui->setupUi(this);

    this->setMouseTracking(true);
    this->move(1480,180);
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    ui->headpic->setMask(QRegion(ui->headpic->rect(),QRegion::RegionType::Ellipse));

    chaticon<<"image2"<<"image3"<<"image4"<<"image5"
           <<"image6"<<"image7"<<"image8"<<"image9";

    chatname<<"王琰璞"<<"徐琨"<<"真姐"
           <<"妈"<<"爸"<<"大哥"
          <<"三弟"<<"郝浩";

    int i;
    for( i=0;i<8;i++){
        QToolButton* chatbtn=new QToolButton(this);
        chatbox=new chat(NULL,chatname[i]);
        chatbtn->setIcon(QPixmap(QString("://%1.jpg").arg(chaticon[i])));
        chatbtn->setIconSize(QSize(80,80));
        chatbtn->setText(chatname[i]);
        //设置透明
        chatbtn->setAutoRaise(true);
        chatbtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
        ui->listvlayout->addWidget(chatbtn);
        list.push_back(chatbtn);
        chatboxs.push_back(chatbox);

        connect(list[i],&QToolButton::clicked,this,[=](){
            emit createchatbox(chatname[i]);
        });




    }
    membernum=i;


    //安装一个event的事件过滤器来处理qobject对象实例的悬停事件，也就是qobject控件的悬停事件要用事件过滤器解决
    //对控件开启悬停事件的可处理
    ui->weaicon->setAttribute(Qt::WA_Hover,true);
    //安装事件过滤器
    ui->weaicon->installEventFilter(this);


    ui->headpic->setMask(QRegion(ui->headpic->rect(),QRegion::RegionType::Ellipse));



}

chatlist::~chatlist()
{
    delete ui;
}

void chatlist::on_close_clicked()
{
    this->hide();
}

void chatlist::mousePressEvent(QMouseEvent *e){
    if(e->button()==Qt::LeftButton){
        pxy=e->globalPos()-this->geometry().topLeft();
    }
    else if((e->button()==Qt::RightButton)){
        return;
    }
}
void chatlist::mouseMoveEvent(QMouseEvent *e){
    if(e->buttons()==Qt::LeftButton){
        this->move(e->globalPos()-pxy);
    }
}



void chatlist::on_min_clicked()
{
   this->showMinimized();
}

void chatlist::on_weaicon_clicked()
{
    wea.show();
}

void chatlist::on_net_3_clicked()
{
    media.show();
}

void chatlist::on_pushButton_8_clicked()
{
    xing.show();
}
